package com.nyist.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

/**
 * 1.
 *
 * @ClassName ProjectNacosNameConfig
 * @Description
 * @Author xiaoyang
 * @Date 2023/04/30/15:19
 */
@Slf4j
@Configuration
public class ProjectNacosNameConfig implements EnvironmentAware {

    @Value("${spring.application.name}")
    private String applicationName;

    @Override
    public void setEnvironment(Environment environment) {
        String propertyName = environment.getProperty("project.name");
        log.info("=====>>> propertyName,init: {}", propertyName);
        if (StringUtils.isEmpty(System.getProperty("project.name"))) {
            System.setProperty("project.name", applicationName);
        }
        propertyName = environment.getProperty("project.name");
        log.info("=====>>> propertyName,set: {}", propertyName);
    }
}
